package com.forekonw.ceyandemo01;

import java.util.*;

public class ListUse {
    public void list(String string){
        List<String> l = new ArrayList<>();
        Map<String,Integer> map = new TreeMap<>();
        for (int i= 0 ;i< string.length();i++){
            for (int j = i+1; j<string.length();j++){
                //截取子串
                String str = string.substring(i,j);
                //将子串保存到list中,并将子串k,v保存到Map中
                if (str.length()!=string.length()){
                    l.add(str);
                    map.put(str,0);
                }
            }
        }
        for (int i = 0 ; i<l.size();i++){
            for (Map.Entry<String,Integer> me:map.entrySet()) {
                if (l.get(i).equals(me.getKey())){
                    me.setValue(me.getValue()+1);
                }
            }
        }
       Set<Map.Entry<String,Integer>> m = map.entrySet();
        Iterator<Map.Entry<String,Integer>> im = m.iterator();
        while (im.hasNext()){
            Map.Entry<String,Integer> mm = im.next();
            if (mm.getValue()>1){
                System.out.println(mm.getKey()+"--"+mm.getValue());
            }
        }
    }
    public static void main(String[] args) {
        ListUse lis = new ListUse();
        lis.list("abcabcabc");
    }
}

